<?php
/**
 * UpdateFilesAction class file.
 *
 * @package   controllers
 * @subpackage patientSignal
 * @since     1.0
 * @filesource
 */

Yii::import('application.controllers.patientSignal.AbstractUploadAction');

/**
 * Action class to display Signal File Update page.
 * User is able to delete uploaded file or upload new file for a signal via the page.
 * This action class will be integrated by PatientSignalController.
 * @see PatientSignalController 
 */
class UpdateFilesAction extends AbstractUploadAction {

	/**
	 * Update the files in a signal record. The user must have appropriate permission to update files.
	 * @param int $id ID from HTTP GET request. Used to look up signal record with this id.
	 * @throws CHttpException if access is denied.
	 * @throws CHttpException if the signal is not editable.
	 */
	public function run($id){
		$model=$this->getController()->loadModel($id);

		//check if the user has right to download a file.
		if(!Yii::app()->user->checkAccess('signalUpdate',array('organizationId'=>$model->organizationId))){
			throw new CHttpException(403,'You do not have permission to update this record.');
		}
		if(!$model->isEditable()){
			throw new CHttpException(403,'This signal cannot be updated.');
		}

		$this->getController()->render('updateFiles',array('model'=>$model,'sessionFiles'=>$this->getSessionFilesForSelection(null,'Do not change'),
			'organization'=>$model->organization));
	}
}